import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count = new CountDownLatch(10);
        System.out.println("比赛开始:");
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + "开始跑");
                    TimeUnit.SECONDS.sleep(3);
                    System.out.println(Thread.currentThread().getName() + "到达终点");
                    count.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }, i + "号选手");
            thread.start();
        }

        TimeUnit.MILLISECONDS.sleep(10);//小于上面休眠时间展示出的效果好
        System.out.println("======比赛进行中======");
        count.await();
        System.out.println("比赛结束");
    }
}
